<template>
  <div>
    <Vheader title="我的红包"></Vheader>
    <div class="RE-tab">
      <div class="Re-tab-item active">未使用</div>
      <div class="Re-tab-item">已使用</div>
      <div class="Re-tab-item">已过期</div>
    </div>
    <div class="Re-wrapper" ref="ReWrapper">
      <div class="Re-container">
        <div class="redEn-list" v-for="item in data">
          <img src="../../common/img/hbbg.png" alt="">
          <div class="redEn-list-content">
            <span class="redEn-banner">{{item.storeDiscount.discountName}}</span>
            <span class="redEn-discount">满{{item.storeDiscount.limitPrice}}减{{item.storeDiscount.price}}</span>
            <span class="redEn-denomination">{{item.storeDiscount.price}}元</span>
            <span class="redEn-date">{{item.storeDiscount.startTime}}至{{item.storeDiscount.endTime}}</span>
            <span class="redEn-state" v-if="state===1"></span>
            <span class="redEn-state used" v-else-if="state===2"></span>
            <span class="redEn-state expired" v-else-if="state===3"></span>
            <span class="redEn-use" v-if="state===1" @click="nowUser(item.id,item.price)">立即使用</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import Vheader from '../../components/header.vue'
  import BScroll from 'better-scroll'
  import axios from '../../axios/axios'

  export default {
    data() {
      return {
        state:1,
        data:[],
        id:'',
      };
    },
    created() {

    },
    mounted() {
      var s=document.querySelectorAll('.Re-tab-item');
      var that=this;
      that.id = that.$route.query.id;
      this.initredEn();
      for(let i=0;i<s.length;i++){
        s[i].onclick=function () {
          for(let j=0;j<s.length;j++){
            s[j].classList.remove('active');
          }
          this.classList.add('active');
          if(i===0){
            that.state=1;
            that.initredEn();
          }else if(i===1){
            that.state=2;
            that.initredEn();
          }else if(i===2){
            that.state=3;
            that.initredEn();
          }
        }
      }
      this._initScroll();
    },
    methods: {
      initredEn:function () {
        var that=this;
        var reddata=JSON.stringify({
          'actionName':'queryListPage',
          'controllerName':'userDiscount',
          'data':[{
            'status': this.state
          },1,10]
        });
        axios.post({
          data:reddata,
          callback(res){
            console.log(res.data);
            console.log(that.state);
            if (res.data.data.result===true){
              that.data=res.data.data.data;
            }
          }
        });
      },
      _initScroll: function () {
        this.scroll = new BScroll(this.$refs.ReWrapper, {click: true})
      },
      nowUser: function(id,money){
        console.log(id)
        if(this.id==1){
          this.$router.push({path: '/nowBuy', query: {id: id,money:money}});
        }
        this.$router.push({path: '/confirmOrder', query: {id: id,money:money}});
      }
    },
    components: {Vheader}
  };
</script>

<style type="text/scss" lang="scss">
  .RE-tab {
    width: 100%;
    height: 44px;
    line-height: 44px;
    text-align: center;
    position: fixed;
    top: 44px;
    background-color: #FFFFFF;
    border-top: solid 1px #f5f5f5;
    box-sizing: border-box;
    display: flex;
    z-index: 100;
    color: #777777;
    .Re-tab-item {
      flex: 1;
    }
    .Re-tab-item.active {
      color: #ef3f00;
    }
    .Re-tab-item.active:after {
      content: '';
      display: block;
      width: 40%;
      height: 2px;
      margin: auto;
      background-color: #ef3f00;
      position: relative;
      top: -2px;
    }
  }

  .Re-wrapper {
    width: 100%;
    height: calc(100% - 88px);
    position: absolute;
    top: 88px;
    .Re-container {
      width: 100%;
      /*background-color: #FFFFFF;*/
      padding: 0 5px 20px 5px;
      box-sizing: border-box;
      .redEn-list {
        width: 100%;
        height: 180px;
        position: relative;
        margin-top: 10px;
        img {
          display: block;
          width: 100%;
          height: 100%;
        }
        .redEn-list-content {
          width: 100%;
          position: relative;
          top: -180px;
          z-index: 2;
          span {
            display: block;
            position: absolute;
          }
          .redEn-banner {
            padding: 3px 5px;
            background-color: rgba(0, 0, 0, 0.3);
            color: #FFFFFF;
            border-radius: 5px;
            top: 5px;
            left: 5px;
          }
          .redEn-discount {
            width: 100%;
            text-align: center;
            font-size: 17px;
            color: #FFFFFF;
            top: 45px;
            left: 0;
          }
          .redEn-denomination {
            font-size: 20px;
            color: #FFFFFF;
            left: 30px;
            top: 90px;
          }
          .redEn-date {
            width: 100%;
            text-align: center;
            top: 105px;
            font-size: 13px;
          }
          .redEn-state {
            width: 67px;
            height: 67px;
            border-radius: 100%;
            top: 90px;
            right: 50px;
            background-size: cover;
          }
          .redEn-state.expired {
            background: url("../../common/img/ygq.png") no-repeat;
          }
          .redEn-state.used {
            background: url("../../common/img/ysy.png") no-repeat;
          }
          .redEn-use {
            width: 100px;
            height: 28px;
            text-align: center;
            line-height: 28px;
            background-color: #f5f5f5;
            font-size: 16px;
            border-radius: 5px;
            top: 140px;
            left: calc((100% - 100px) / 2);
            color: #575757;

          }
        }
      }
    }
  }
</style>
